/*
 * DumpTruck.java
 *
 * Created on October 22, 2007, 12:44 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package dumptruck;

//import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import simulationengine.animation.AnimationCommand;
import simulationengine.animation.AnimationEngine;
import simulationengine.process.Consumer;
import simulationengine.process.Resource;
import simulationengine.process.Distribution;

/**
 *
 * @author Eric Drucker
 */
public class DumpTruck
{
	
	/** Creates a new instance of DumpTruck */
	public DumpTruck()
	{
	}
	
	
	public static void main(String args[])
	{
            final int endOfSimulation = 100000;

            //Time Distributions
             //Arrival        arriveTimeDistribution = new Arrival();
             Loading        loading1 = new Loading();
             Loading        loading2 = new Loading();
             Weighing       weighing = new Weighing();
             Traveling      traveling = new Traveling();
             //Distribution   exitTimeStats = new Distribution();
                   
             //Resources
                //Minor resources
             Resource loader1 = new Resource(loading1,0);
             Resource loader2 = new Resource(loading2,1);
             Resource route1 = new Resource(traveling,0);
             Resource route2 = new Resource(traveling,1);
             Resource route3 = new Resource(traveling,2);
             Resource route4 = new Resource(traveling,3);
             Resource route5 = new Resource(traveling,4);
             Resource route6 = new Resource(traveling,5);
             
                //Major resources
             Resource scale = new Resource(weighing,null,0);
             Resource loaderComposite = new Resource(2,scale,true,false);
             Resource deliveryComposite = new Resource(6,loaderComposite,true,true);
             
             scale.nextResource = deliveryComposite;
             
             deliveryComposite.nextAvailableResourceQ.put(route1);
             deliveryComposite.nextAvailableResourceQ.put(route2);
             deliveryComposite.nextAvailableResourceQ.put(route3);
             deliveryComposite.nextAvailableResourceQ.put(route4);
             deliveryComposite.nextAvailableResourceQ.put(route5);
             deliveryComposite.nextAvailableResourceQ.put(route6);
             
             loaderComposite.nextAvailableResourceQ.put(loader1);
             loaderComposite.nextAvailableResourceQ.put(loader2);
             
		   //LinkedBlockingQueue<AnimationCommand> commands = new LinkedBlockingQueue<AnimationCommand>();
                    PriorityBlockingQueue<AnimationCommand> commands = new PriorityBlockingQueue<AnimationCommand>();
		   
             Consumer truck1 = new Consumer(endOfSimulation,0,loaderComposite,0, commands);
                commands.add(new AnimationCommand(AnimationCommand.Command.ADD, 0, 0, 0, 0));
             Consumer truck2 = new Consumer(endOfSimulation,0,loaderComposite,1, commands);
                commands.add(new AnimationCommand(AnimationCommand.Command.ADD, 0, 1, 0, 0));
             Consumer truck3 = new Consumer(endOfSimulation,0,loaderComposite,2, commands);
                commands.add(new AnimationCommand(AnimationCommand.Command.ADD, 0, 2, 0, 0));
             Consumer truck4 = new Consumer(endOfSimulation,0,loaderComposite,3, commands);
                commands.add(new AnimationCommand(AnimationCommand.Command.ADD, 0, 3, 0, 0));
             Consumer truck5 = new Consumer(endOfSimulation,0,loaderComposite,4, commands);
                commands.add(new AnimationCommand(AnimationCommand.Command.ADD, 0, 4, 0, 0));
             Consumer truck6 = new Consumer(endOfSimulation,0,loaderComposite,5, commands);
                commands.add(new AnimationCommand(AnimationCommand.Command.ADD, 0, 5, 0, 0));
             
             System.out.println("Starting DumpTruck Simulation");
             
             truck1.start();
             truck2.start();
             truck3.start();
             truck4.start();
             truck5.start();
             truck6.start();
		   
		   int [] serviceLocations = {2, 1};
		   AnimationEngine a = new AnimationEngine("Dump Truck", commands, endOfSimulation, serviceLocations);
        }
        
        public static class Loading extends simulationengine.process.Distribution
        {
            public Loading()
            {
                super();
            }
            
            public int next()
            {
                //Loading service times
                randInt = rand.nextInt(100);
                if(randInt < 30)
                        time = 5;
                else if(randInt < 80)
                        time = 10;
                else if(randInt < 100)
                        time = 15;
                
                return time;
            }
        }
        
        public static class Weighing extends simulationengine.process.Distribution
        {
            public Weighing()
            {
                super();
            }
            
            public int next()
            {
                //Weighing service times
                randInt = rand.nextInt(100);
                if(randInt < 70)
                        time = 12;
                else if(randInt < 100)
                        time = 16;
            
                return time;
            }
        }
        
        public static class Traveling extends simulationengine.process.Distribution
        {
            public Traveling()
            {
                super();
            }
            
            public int next()
            {
                //Traveling service times
                randInt = rand.nextInt(100);
                if(randInt < 40)
                        time = 40;
                else if(randInt < 70)
                        time = 60;
                else if(randInt < 90)
                        time = 80;
                else if(randInt < 100)
                        time = 100;
                
                return time;
            }
        }
}
